package com.thinkit.bigdata.web.model.bus;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@JsonIgnoreProperties(ignoreUnknown = true)
public class BusModel {
    private Long id;

    private String provincecode;

    private String name;

    private Integer fullscore;

    private String note;

    private Long typeid;

    private Integer poststatus;

    private Integer testtimes;

    private Date createtime;

    private Long createuserid;

    private Date lastupdatetime;

    private Long lastupdateuserid;

    private Date onsettime;

    //多表联查
    private String modeltypename; //模型分类名

    private String areaname; //地区名

    private String username; //用户名
    //一对多
    private List<BusModelRule> modelrulelist; //规列表

    public List<BusModelRule> getModelrulelist() {
        return modelrulelist;
    }

    public void setModelrulelist(List<BusModelRule> modelrulelist) {
        this.modelrulelist = modelrulelist;
    }

    public String getModeltypename() {
        return modeltypename;
    }

    public void setModeltypename(String modeltypename) {
        this.modeltypename = modeltypename;
    }

    public String getAreaname() {
        return areaname;
    }

    public void setAreaname(String areaname) {
        this.areaname = areaname;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public BusModel() {
    }

    public BusModel(Long id, String provincecode, String name, Integer fullscore, String note, Long typeid, Integer poststatus, Integer testtimes, Date createtime, Long createuserid, Date lastupdatetime, Long lastupdateuserid, Date onsettime) {
        this.id = id;
        this.provincecode = provincecode;
        this.name = name;
        this.fullscore = fullscore;
        this.note = note;
        this.typeid = typeid;
        this.poststatus = poststatus;
        this.testtimes = testtimes;
        this.createtime = createtime;
        this.createuserid = createuserid;
        this.lastupdatetime = lastupdatetime;
        this.lastupdateuserid = lastupdateuserid;
        this.onsettime = onsettime;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getProvincecode() {
        return provincecode;
    }

    public void setProvincecode(String provincecode) {
        this.provincecode = provincecode == null ? null : provincecode.trim();
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name == null ? null : name.trim();
    }

    public Integer getFullscore() {
        return fullscore;
    }

    public void setFullscore(Integer fullscore) {
        this.fullscore = fullscore;
    }

    public String getNote() {
        return note;
    }

    public void setNote(String note) {
        this.note = note == null ? null : note.trim();
    }

    public Long getTypeid() {
        return typeid;
    }

    public void setTypeid(Long typeid) {
        this.typeid = typeid;
    }

    public Integer getPoststatus() {
        return poststatus;
    }

    public void setPoststatus(Integer poststatus) {
        this.poststatus = poststatus;
    }

    public Integer getTesttimes() {
        return testtimes;
    }

    public void setTesttimes(Integer testtimes) {
        this.testtimes = testtimes;
    }

    public Date getCreatetime() {
        return createtime;
    }

    @JsonDeserialize(using = CustomJsonDateDeserializer.class)
    public void setCreatetime(Date createtime) {
        this.createtime = createtime;
    }

    public Long getCreateuserid() {
        return createuserid;
    }

    public void setCreateuserid(Long createuserid) {
        this.createuserid = createuserid;
    }

    public Date getLastupdatetime() {
        return lastupdatetime;
    }

    @JsonDeserialize(using = CustomJsonDateDeserializer.class)
    public void setLastupdatetime(Date lastupdatetime) {
        this.lastupdatetime = lastupdatetime;
    }

    public Long getLastupdateuserid() {
        return lastupdateuserid;
    }

    public void setLastupdateuserid(Long lastupdateuserid) {
        this.lastupdateuserid = lastupdateuserid;
    }

    public Date getOnsettime() {
        return onsettime;
    }

    public void setOnsettime(Date onsettime) {
        this.onsettime = onsettime;
    }

    @Override
    public boolean equals(Object obj) {
        BusModel model = (BusModel) obj;
        return id == model.getId();
    }
}

class CustomJsonDateDeserializer extends JsonDeserializer<Date> {
    @Override
    public Date deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String date = jp.getText();
        try {
            return format.parse(date);
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
    }
}